#ifndef CURLEASYHEADERHASBEENINCLUDED 
#define CURLEASYHEADERHASBEENINCLUDED

#include <curl/curl.h>

#define DOWNLOADSPEEDDIVISOR 1000
#define DOWNLOADSPEEDSTRING "kbps"

typedef struct{
	char *memory;
	size_t size;
}memoryStruct;

typedef struct{
	char* url; // malloc
	char* destFile; // malloc
	char _isDone;
	//
	curl_off_t downloadGoal;
	curl_off_t downloadSpeed; // In kbps
	// Used to calculate download speed
	long lastMilliseconds;
	curl_off_t lastDownloaded;
	//
	CURL* _personalCURL;
}downloadInstance;

void* _downloadFileSyncThread(void* _passedData);
int _downloadUpdateProgress(void* ptr, curl_off_t downloadGoal, curl_off_t amoutDownloaded, curl_off_t _a, curl_off_t _b);
struct curl_slist *newCurlHeaders();
void applyCurlHeaders(CURL* _passedCurl, struct curl_slist* _passedHeaders);
void curlSetContentType(char* _passedType, struct curl_slist** _passedHeaders);
size_t curlWriteDataFile(void *ptr, size_t size, size_t nmemb, void *stream);
size_t curlWriteDiscardData(void *ptr, size_t size, size_t nmemb, void *stream);
size_t curlWriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp);
void deleteCurl(CURL* _passedCurl);
char downloadFileBlocking(CURL* _passedCurl, char* passedUrl, char* passedFilename);
void downloadFileSync(downloadInstance* _passedDownloadInfo);
void downloadWebpageData(CURL* _passedCurl, memoryStruct* chunkToDownloadTo, char* url);
void freeCurlHeaders(struct curl_slist* _passedHeaders);
long getMilliseconds();
void globalDeleteCurl();
void globalInitCurl();
CURL* newCurl();
void resetCurlSettings(CURL* _passedCurl);
void setUpCurlPost(CURL* _passedCurl, char* _postData);

#endif